﻿using System;
using System.Windows;
using Autofac;
using Phoenix;
using Phoenix.Frames;
using TodoApp.Data;
using Phoenix.Extensions.Autofac;

namespace TodoApp
{
    public partial class App
    {
        protected override void ConfigurePhoenixHostBuilder(IPhoenixHostBuilder hostBuilder)
        {
            hostBuilder.Configuration.StartupOptions = PhoenixStartupOptions.ShowShellAfterInitialNavigation;
            hostBuilder.Configuration.DefaultControllerAction = "Tasks.Index";
            hostBuilder.Configuration.DefaultControllerActionArguments = new object[] { 1 };
            hostBuilder.SetNavigationFrameFactory(() => new TransitionNavigationFrame());
        }

        protected override void ConfigureContainer(ContainerBuilder containerBuilder)
        {
            typeof(App).Assembly.RegisterControllers(containerBuilder);
            typeof(App).Assembly.RegisterViewModels(containerBuilder);

            containerBuilder
                .RegisterType<TaskRepository>()
                .As<ITaskRepository>()
                .SingleInstance();
        }

        protected override Window CreateShell(INavigationFrame navigationFrame)
        {
            return new Shell
                {
                    Content = navigationFrame
                };
        }
    }
}
